
package com.shop.cloud.mall.api.controller;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.binarywang.wxpay.bean.notify.WxPayNotifyResponse;
import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult;
import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest;
import com.github.binarywang.wxpay.exception.WxPayException;
import com.shop.cloud.common.core.constant.CommonConstants;
import com.shop.cloud.common.core.constant.SecurityConstants;
import com.shop.cloud.common.core.util.LocalDateTimeUtils;
import com.shop.cloud.common.core.util.R;
import com.shop.cloud.common.data.tenant.TenantContextHolder;
import com.shop.cloud.common.portal.constant.PortalConstants;
import com.shop.cloud.common.security.annotation.Inside;
import com.shop.cloud.common.portal.annotation.ApiLogin;
import com.shop.cloud.mall.common.config.MallConfigProperties;
import com.shop.cloud.mall.api.service.*;
import com.shop.cloud.mall.common.constant.MallConstants;
import com.shop.cloud.mall.common.constant.MallReturnCode;
import com.shop.cloud.mall.common.dto.PlaceOrderDTO;
import com.shop.cloud.mall.common.entity.*;
import com.shop.cloud.mall.common.enums.OrderInfoEnum;
import com.shop.cloud.upms.common.entity.SysTenant;
import com.shop.cloud.upms.common.feign.FeignTenantService;
import com.shop.cloud.weixin.common.feign.FeignWxTemplateMsgService;
import com.shop.cloud.pay.common.dto.AliBaseRequest;
import com.shop.cloud.weixin.common.constant.WxConstant;
import com.shop.cloud.weixin.common.dto.WxTemplateMsgSendDTO;
import com.shop.cloud.common.portal.entity.ThirdSession;
import com.shop.cloud.common.portal.util.ThirdSessionHolder;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

/**
 * 商城订单
 *
 * @author
 * @date 2019-09-10 15:21:22
 */
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/orderinfo")
@Tag(description = "orderinfo", name = "商城订单API")
public class OrderInfoController {

    private final OrderInfoService orderInfoService;
	private final com.shop.cloud.pay.common.feign.FeignPayService feignPayService;
	private final MallConfigProperties mallConfigProperties;
	private final OrderLogisticsService orderLogisticsService;
	private final GrouponInfoService grouponInfoService;
	private final GrouponUserService grouponUserService;
	private final BargainUserService bargainUserService;
	private final ShopInfoService shopInfoService;
	private final FeignWxTemplateMsgService feignWxTemplateMsgService;
	private final FeignTenantService feignTenantService;

	/**
	* 分页查询
	* @param page 分页对象
	* @param orderInfo 商城订单
	* @return
	*/
	@Operation(summary = "分页查询")
    @GetMapping("/page")
	@ApiLogin
    public R getPage(Page page, OrderInfo orderInfo) {
		orderInfo.setUserId(ThirdSessionHolder.getUserId());
        return R.ok(orderInfoService.page2(page,orderInfo));
    }

    /**
    * 通过id查询商城订单
    * @param id
    * @return R
    */
	@Operation(summary = "通过id查询商城订单")
    @GetMapping("/{id}")
    public R getById(@PathVariable("id") String id){
		return R.ok(orderInfoService.getById2(id));
    }

	/**
	 * 新增订单集合（据店铺ID分组）
	 * @param mapPlaceOrderDTO 订单集合，已根据店铺分组
	 * @return R
	 */
	@Operation(summary = "新增订单集合（据店铺ID分组）")
	@PostMapping("/map")
	@ApiLogin
	public R orderAddMap(HttpServletRequest request, @RequestBody Map<String, PlaceOrderDTO> mapPlaceOrderDTO){
		//校验租户的状态和过期时间
		SysTenant sysTenant = feignTenantService.getById(TenantContextHolder.getTenantId(), SecurityConstants.FROM_IN).getData();
		//租户锁定
		if(CommonConstants.STATUS_LOCK.equals(sysTenant.getStatus())){
			return R.failed("该商城已被锁定");
		}
		//租户已过期
		if(sysTenant.getExpireTime().isBefore(LocalDateTime.now())){
			return R.failed("该商城已欠费到期，请联系商城管理员充值");
		}
		List<OrderInfo> listOrderInfo = orderInfoService.orderAddMap(request, mapPlaceOrderDTO);
		if(CollectionUtil.isEmpty(listOrderInfo)){
			return R.failed(MallReturnCode.ERR_70003.getCode(), MallReturnCode.ERR_70003.getMsg());
		}
		listOrderInfo.forEach(orderInfo -> {
			//发送微信模板消息
			try {
				WxTemplateMsgSendDTO wxTemplateMsgSendDTO = new WxTemplateMsgSendDTO();
				wxTemplateMsgSendDTO.setMallUserId(orderInfo.getUserId());
				wxTemplateMsgSendDTO.setUseType(WxConstant.WX_TMP_USE_TYPE_1);
				wxTemplateMsgSendDTO.setPage("pages/order/order-detail/index?id="+orderInfo.getId());
				Map<String, Object> data = new HashMap();
				Map<String, Object> map = BeanUtil.beanToMap(orderInfo);
				for(String mapKey: map.keySet()){
					data.put("order." + mapKey, map.get(mapKey));
				}
				wxTemplateMsgSendDTO.setData(data);
				feignWxTemplateMsgService.sendTemplateMsgMp(wxTemplateMsgSendDTO, SecurityConstants.FROM_IN);
			}catch (Exception e){
				log.error("发送微信模板消息出错："+e.getMessage(), e);
			}
		});
		return R.ok(listOrderInfo);
	}

    /**
    * 通过id删除商城订单
    * @param id
    * @return R
    */
	@Operation(summary = "通过id删除商城订单")
    @DeleteMapping("/{id}")
    public R removeById(@PathVariable String id){
		OrderInfo orderInfo = orderInfoService.getById(id);
		if(orderInfo == null){
			return R.failed(MallReturnCode.ERR_70005.getCode(), MallReturnCode.ERR_70005.getMsg());
		}
		if(!OrderInfoEnum.STATUS_5.getValue().equals(orderInfo.getStatus()) || CommonConstants.YES.equals(orderInfo.getIsPay())){
			return R.failed(MallReturnCode.ERR_70001.getCode(), MallReturnCode.ERR_70001.getMsg());
		}
		return R.ok(orderInfoService.removeById(id));
    }

	/**
	 * 取消商城订单
	 * @param id 商城订单
	 * @return R
	 */
	@Operation(summary = "取消商城订单")
	@PutMapping("/cancel/{id}")
	public R orderCancel(@PathVariable String id){
		OrderInfo orderInfo = orderInfoService.getById(id);
		if(orderInfo == null){
			return R.failed(MallReturnCode.ERR_70005.getCode(), MallReturnCode.ERR_70005.getMsg());
		}
		if(!CommonConstants.NO.equals(orderInfo.getIsPay())){//只有未支付订单能取消
			return R.failed(MallReturnCode.ERR_70001.getCode(), MallReturnCode.ERR_70001.getMsg());
		}
		orderInfoService.orderCancel(orderInfo);
		return R.ok();
	}

	/**
	 * 取消商城订单（服务间调用）
	 * @param id 商城订单
	 * @return R
	 */
	@Operation(summary = "取消商城订单（服务间调用）")
	@PutMapping("/inside/cancel/{id}")
	@Inside
	public R orderCancelInside(@PathVariable String id){
		OrderInfo orderInfo = orderInfoService.getById(id);
		if(orderInfo == null){
			return R.failed(MallReturnCode.ERR_70005.getCode(), MallReturnCode.ERR_70005.getMsg());
		}
		if(!CommonConstants.NO.equals(orderInfo.getIsPay())){//只有未支付订单能取消
			return R.failed(MallReturnCode.ERR_70001.getCode(), MallReturnCode.ERR_70001.getMsg());
		}
		orderInfoService.orderCancel(orderInfo);
		return R.ok();
	}

	/**
	 * 商城订单确认收货
	 * @param id 商城订单
	 * @return R
	 */
	@Operation(summary = "商城订单确认收货")
	@PutMapping("/receive/{id}")
	public R orderReceive(@PathVariable String id){
		OrderInfo orderInfo = orderInfoService.getById(id);
		if(orderInfo == null){
			return R.failed(MallReturnCode.ERR_70005.getCode(), MallReturnCode.ERR_70005.getMsg());
		}
		if(!OrderInfoEnum.STATUS_2.getValue().equals(orderInfo.getStatus())){//只有待收货订单能确认收货
			return R.failed(MallReturnCode.ERR_70001.getCode(), MallReturnCode.ERR_70001.getMsg());
		}
		orderInfoService.orderReceive(orderInfo);
		return R.ok();
	}

	/**
	 * 商城订单自提（服务间调用）
	 * @param id 商城订单
	 * @return R
	 */
	@Operation(summary = "商城订单自提（服务间调用）")
	@PutMapping("/inside/takegoods/{id}")
	@Inside
	public R orderTakeGoodsInside(@PathVariable String id){
		OrderInfo orderInfo = orderInfoService.getById(id);
		if(orderInfo == null){
			return R.failed(MallReturnCode.ERR_70005.getCode(), MallReturnCode.ERR_70005.getMsg());
		}
		if(!MallConstants.DELIVERY_WAY_2.equals(orderInfo.getDeliveryWay())
				&& !OrderInfoEnum.STATUS_1.getValue().equals(orderInfo.getStatus())){//只有待自提订单能确认收货
			return R.failed(MallReturnCode.ERR_70001.getCode(), MallReturnCode.ERR_70001.getMsg());
		}
		orderInfoService.orderReceive(orderInfo);
		return R.ok();
	}

	/**
	 * 调用统一下单接口，并组装生成支付所需参数对象.
	 *
	 * @param orderInfo 统一下单请求参数
	 * @return 返回 {@link com.github.binarywang.wxpay.bean.order}包下的类对象
	 */
	@Operation(summary = "调用统一下单接口")
	@PostMapping("/unifiedOrder")
	@ApiLogin
	public R unifiedOrder(HttpServletRequest request, @RequestBody OrderInfo orderInfo){
		String returnUrl = orderInfo.getReturnUrl();
		String quitUrl = orderInfo.getQuitUrl();
		String tradeType = orderInfo.getTradeType();
		String paymentType = orderInfo.getPaymentType();
		String appId = orderInfo.getAppId();
		ThirdSession thirdSession = ThirdSessionHolder.getThirdSession();
		orderInfo = orderInfoService.getById(orderInfo.getId());
		if(orderInfo == null){
			return R.failed(MallReturnCode.ERR_70005.getCode(), MallReturnCode.ERR_70005.getMsg());
		}
		if(!CommonConstants.NO.equals(orderInfo.getIsPay())){//只有未支付的详单能发起支付
			return R.failed(MallReturnCode.ERR_70004.getCode(), MallReturnCode.ERR_70004.getMsg());
		}
		if(MallConstants.ORDER_TYPE_1.equals(orderInfo.getOrderType())) {//砍价订单
			BargainUser bargainUser = bargainUserService.getById(orderInfo.getRelationId());
			if(CommonConstants.YES.equals(bargainUser.getIsBuy())){
				return R.failed(MallReturnCode.ERR_80006.getCode(), MallReturnCode.ERR_80006.getMsg());
			}
		}
		if(MallConstants.ORDER_TYPE_2.equals(orderInfo.getOrderType())){//拼团订单
			GrouponInfo grouponInfo = grouponInfoService.getOne(Wrappers.<GrouponInfo>lambdaQuery()
					.eq(GrouponInfo::getId,orderInfo.getMarketId())
					.eq(GrouponInfo::getEnable,CommonConstants.YES)
					.lt(GrouponInfo::getValidBeginTime,LocalDateTime.now())
					.gt(GrouponInfo::getValidEndTime,LocalDateTime.now()));
			if(grouponInfo == null){//判断拼团的有效性
				return R.failed(MallReturnCode.ERR_80010.getCode(), MallReturnCode.ERR_80010.getMsg());
			}
			if(StrUtil.isNotBlank(orderInfo.getRelationId())){
				//校验当前用户是否已经参与
				GrouponUser grouponUser1 = grouponUserService.getOne(Wrappers.<GrouponUser>lambdaQuery()
						.eq(GrouponUser::getGroupId,orderInfo.getRelationId())
						.eq(GrouponUser::getUserId,thirdSession.getUserId()));
				if(grouponUser1 != null){
					return R.failed(MallReturnCode.ERR_80012.getCode(), MallReturnCode.ERR_80012.getMsg());
				}
				//校验拼团人数
				GrouponUser grouponUser = grouponUserService.getById(orderInfo.getRelationId());
				Integer havCountGrouponing = grouponUserService.selectCountGrouponing(orderInfo.getRelationId());
				if(havCountGrouponing >= grouponUser.getGrouponNum()){
					return R.failed(MallReturnCode.ERR_80011.getCode(), MallReturnCode.ERR_80011.getMsg());
				}
			}
		}
		ShopInfo shopInfo = shopInfoService.getById(orderInfo.getShopId());
		if(CommonConstants.NO.equals(shopInfo.getEnable())){
			return R.failed(MallReturnCode.ERR_80044.getCode(), MallReturnCode.ERR_80044.getMsg());
		}
		if(orderInfo.getPaymentPrice().compareTo(BigDecimal.ZERO)==0){//0元购买不调支付
			orderInfo.setPaymentTime(LocalDateTime.now());
			orderInfoService.notifyOrder(orderInfo);
			return R.ok();
		}
		if(StrUtil.isBlank(paymentType)){
			return R.failed(MallReturnCode.ERR_70002.getCode(), MallReturnCode.ERR_70002.getMsg());
		}
		String body = orderInfo.getName();
		body = body.length() > 40 ? body.substring(0,39) : body;
		//微信支付
		if(MallConstants.ORDER_PAYMENT_TYPE_1.equals(paymentType)){
			//更新编号防止不同终端微信报重复订单号
			//orderInfo.setOrderNo(IdUtil.getSnowflake(0,0).nextIdStr());
			orderInfoService.updateById(orderInfo);
			WxPayUnifiedOrderRequest wxPayUnifiedOrderRequest = new WxPayUnifiedOrderRequest();
			wxPayUnifiedOrderRequest.setSubMchId(shopInfo.getWxMchId());
			wxPayUnifiedOrderRequest.setBody(body);
			wxPayUnifiedOrderRequest.setOutTradeNo(orderInfo.getOrderNo());
			wxPayUnifiedOrderRequest.setTotalFee(orderInfo.getPaymentPrice().multiply(new BigDecimal(100)).intValue());
			wxPayUnifiedOrderRequest.setTradeType(tradeType);
			wxPayUnifiedOrderRequest.setNotifyUrl(mallConfigProperties.getNotifyHost()+MallConstants.SERVER_ROUTE_NAME_MALLAPI+ PortalConstants.ORDER_NOTIFY_URL_WX+"/"+orderInfo.getTenantId());
			wxPayUnifiedOrderRequest.setSpbillCreateIp(request.getRemoteAddr());
			wxPayUnifiedOrderRequest.setSubOpenid(thirdSession.getOpenId());
			wxPayUnifiedOrderRequest.setSubAppId(thirdSession.getAppId());
			wxPayUnifiedOrderRequest.setAppid(appId);
			return feignPayService.unifiedOrderWx(wxPayUnifiedOrderRequest, SecurityConstants.FROM_IN);
		}else if(MallConstants.ORDER_PAYMENT_TYPE_2.equals(paymentType)){//支付宝支付
			Map<String, Object> params = new HashMap<>();
			params.put("tradeType",tradeType);
			params.put("outTradeNo",orderInfo.getOrderNo());
			params.put("totalAmount",orderInfo.getPaymentPrice().toString());
			params.put("notifyUrl",mallConfigProperties.getNotifyHost()+MallConstants.SERVER_ROUTE_NAME_MALLAPI + PortalConstants.ORDER_NOTIFY_URL_ALI + "/" + orderInfo.getTenantId());
			params.put("returnUrl",returnUrl);
			params.put("quitUrl",quitUrl);
			params.put("subject",body);
			AliBaseRequest aliBaseRequest = new AliBaseRequest();
			aliBaseRequest.setAppAuthToken(shopInfo.getAliAuthToken());
			aliBaseRequest.setParams(params);
			return feignPayService.unifiedOrderAli(aliBaseRequest, SecurityConstants.FROM_IN);
		}else if(MallConstants.ORDER_PAYMENT_TYPE_3.equals(paymentType)){//余额支付
			orderInfo.setPaymentType(paymentType);
			orderInfoService.balancePay(orderInfo);
			return R.ok();
		}else{
			return R.failed("无此支付类型");
		}
	}

	/**
	 * 支付回调（微信）
	 * @param xmlData
	 * @return
	 * @throws WxPayException
	 */
	@Operation(summary = "支付回调（微信）")
	@PostMapping("/notify-order-wx/{tenantId}")
	public String notifyOrderWx(@RequestBody String xmlData, @PathVariable("tenantId") String tenantId) {
		log.info("支付回调（微信）:"+xmlData);
		TenantContextHolder.setTenantId(tenantId);//设置租户ID
		R<WxPayOrderNotifyResult> r = feignPayService.notifyOrderWx(xmlData, SecurityConstants.FROM_IN);
		if(r.isOk()){
			WxPayOrderNotifyResult notifyResult = r.getData();
			OrderInfo orderInfo = orderInfoService.getOne(Wrappers.<OrderInfo>lambdaQuery()
					.eq(OrderInfo::getOrderNo,notifyResult.getOutTradeNo()));
			if(orderInfo != null){
				orderInfo.setTradeType(notifyResult.getTradeType());
				if(orderInfo.getPaymentPrice().multiply(new BigDecimal(100)).intValue() == notifyResult.getTotalFee()){
					String timeEnd = notifyResult.getTimeEnd();
					LocalDateTime paymentTime = LocalDateTimeUtils.parse(timeEnd);
					orderInfo.setPaymentTime(paymentTime);
					orderInfo.setTransactionId(notifyResult.getTransactionId());
					orderInfo.setPaymentType(MallConstants.ORDER_PAYMENT_TYPE_1);
					orderInfoService.notifyOrder(orderInfo);
					return WxPayNotifyResponse.success("成功");
				}else{
					return WxPayNotifyResponse.fail("付款金额与订单金额不等");
				}
			}else{
				return WxPayNotifyResponse.fail("无此订单");
			}
		}else{
			return WxPayNotifyResponse.fail(r.getMsg());
		}
	}

	/**
	 * 支付回调（支付宝）
	 * @param request
	 * @return
	 * @throws
	 */
	@Operation(summary = "支付回调（支付宝）")
	@ResponseBody
	@PostMapping("/notify-order-ali/{tenantId}")
	public String notifyOrderAli(HttpServletRequest request, @PathVariable("tenantId") String tenantId) {
		log.info("支付回调（支付宝）");
		Map<String, String> params = new HashMap<>();
		Map requestParams = request.getParameterMap();
		for (Iterator iter = requestParams.keySet().iterator(); iter.hasNext(); ) {
			String name = (String) iter.next();
			String[] values = (String[]) requestParams.get(name);
			String valueStr = "";
			for (int i = 0; i < values.length; i++) {
				valueStr = (i == values.length - 1) ? valueStr + values[i] : valueStr + values[i] + ",";
			}
			params.put(name, valueStr);
		}
		String appId = request.getParameter("app_id");
		if(StrUtil.isBlank(appId)){
			return "appId不能为空";
		}
		TenantContextHolder.setTenantId(tenantId);//设置租户ID
		OrderInfo orderInfo = orderInfoService.getOne(Wrappers.<OrderInfo>lambdaQuery()
				.eq(OrderInfo::getOrderNo,request.getParameter("out_trade_no")));
		if(orderInfo == null){
			log.error("无此订单out_trade_no："+request.getParameter("out_trade_no"));
			return "无此订单";
		}
//		orderInfo.setTradeType(notifyResult.getTradeType());
		if(orderInfo.getPaymentPrice().compareTo(new BigDecimal(request.getParameter("total_amount"))) == 0){
			LocalDateTime paymentTime = LocalDateTimeUtils.parse(request.getParameter("gmt_payment"));
			orderInfo.setPaymentTime(paymentTime);
			orderInfo.setTransactionId(request.getParameter("trade_no"));
			orderInfo.setPaymentType(MallConstants.ORDER_PAYMENT_TYPE_2);
			orderInfoService.notifyOrder(orderInfo);
			log.info("支付回调（支付宝）success");
			return "success";
		}else{
			log.error("付款金额与订单金额不等out_trade_no："+request.getParameter("out_trade_no"));
			return "付款金额与订单金额不等";
		}

	}

	/**
	 * 物流信息回调
	 * @param request
	 * @return
	 */
	@Operation(summary = "物流信息回调")
	@PostMapping("/notify-logisticsr")
	public String notifyLogisticsr(HttpServletRequest request, HttpServletResponse response) {
		String param = request.getParameter("param");
		String tenantId = request.getParameter("tenantId");
		TenantContextHolder.setTenantId(tenantId);
		log.info("物流信息回调:"+param);
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("result",false);
		map.put("returnCode","500");
		map.put("message","保存失败");
		try {
			JSONObject jsonObject = JSONUtil.parseObj(param);
			orderInfoService.notifyLogisticsr(jsonObject);
			map.put("result",true);
			map.put("returnCode","200");
			map.put("message","保存成功");
			//这里必须返回，否则认为失败，过30分钟又会重复推送。
			response.getWriter().print(JSONUtil.parseObj(map));
		} catch (Exception e) {
			map.put("message","保存失败" + e.getMessage());
			//保存失败，服务端等30分钟会重复推送。
			try {
				response.getWriter().print(JSONUtil.parseObj(map));
			} catch (Exception e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
		}
		return null;
	}

	/**
	 * 通过物流id查询订单物流
	 * @param logisticsId
	 * @return R
	 */
	@Operation(summary = "通过物流id查询订单物流")
	@GetMapping("/orderlogistics/{logisticsId}")
	public R getOrderLogistics(@PathVariable("logisticsId") String logisticsId){
		return R.ok(orderLogisticsService.getById(logisticsId));
	}

	/**
	 * 统计各个状态订单计数
	 * @param orderInfo
	 * @return R
	 */
	@Operation(summary = "统计各个状态订单计数")
	@GetMapping("/countAll")
	@ApiLogin
	public R count(OrderInfo orderInfo){
		orderInfo.setUserId(ThirdSessionHolder.getUserId());
		Map<String, Long> countAll = new HashMap<>();
		countAll.put(OrderInfoEnum.STATUS_0.getValue(),orderInfoService.count(Wrappers.query(orderInfo).lambda()
				.isNull(OrderInfo::getStatus)
				.eq(OrderInfo::getIsPay,CommonConstants.NO)));

		countAll.put(OrderInfoEnum.STATUS_1.getValue(),orderInfoService.count(Wrappers.query(orderInfo).lambda()
				.eq(OrderInfo::getStatus,OrderInfoEnum.STATUS_1.getValue())
				.eq(OrderInfo::getIsPay,CommonConstants.YES)));

		countAll.put(OrderInfoEnum.STATUS_2.getValue(),orderInfoService.count(Wrappers.query(orderInfo).lambda()
				.eq(OrderInfo::getStatus,OrderInfoEnum.STATUS_2.getValue())
				.eq(OrderInfo::getIsPay,CommonConstants.YES)));

		countAll.put(OrderInfoEnum.STATUS_3.getValue(),orderInfoService.count(Wrappers.query(orderInfo).lambda()
				.eq(OrderInfo::getStatus,OrderInfoEnum.STATUS_3.getValue())
				.eq(OrderInfo::getIsPay,CommonConstants.YES)
				.eq(OrderInfo::getAppraisesStatus,MallConstants.APPRAISES_STATUS_0)));
		return R.ok(countAll);
	}

}
